package com.dragon.app.concurrent;

public class VolatileTest {

	public static void main(String[] args) {
		DataTest data = new DataTest();

		new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				data.change();
			}
		}).start();

		while (data.number == 0) {
			
		}
		
		System.out.println("exit...");
	}
	
	static class DataTest{
		int number = 0; //不可见
		//volatile int number = 0; //可见
		
		public void change() {
			this.number = 60;
		}
	}

}
